﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Fwk.Controles;

namespace Fwk.Presentacion
{
    public class PaginaABM: PaginaBase
    {
        public enum Accion
        {
            Nuevo,
            Modificar,
            Ninguno
        }

        public Accion AccionABM 
        { 
            get 
            {
                if (ViewState["AccionABM"] != null)
                {
                    return (Accion)ViewState["AccionABM"];
                }
                else 
                {
                    return Accion.Ninguno;
                }
            }
            set 
            {
                ViewState["AccionABM"] = value;
                HabilitarControles();
            } 
        }

        private void HabilitarControles() 
        {
            //voy a la pagina base y busco el control
            Boton btnNuevo = base.Find<Boton>("btnNuevo");
            Boton btnModificar = base.Find<Boton>("btnModificar");
            Boton btnEliminar = base.Find<Boton>("btnEliminar");
            Boton btnAceptar = base.Find<Boton>("btnAceptar");
            Boton btnCancelar = base.Find <Boton>("btnCancelar");
            Boton btnBuscar = base.Find<Boton>("btnBuscar");
            Boton btnLimpiar = base.Find<Boton>("btnLimpiar");
           
            if (AccionABM.Equals(Accion.Nuevo) || AccionABM.Equals(Accion.Modificar))
            {
                btnNuevo.Enabled = false;
                btnModificar.Enabled = false;
                btnEliminar.Enabled = false;
                btnBuscar.Enabled = false;
                btnLimpiar.Enabled = false;             
                btnAceptar.Enabled = true;
                btnCancelar.Enabled = true;
            }
            else 
            {
                btnNuevo.Enabled = true;
                btnModificar.Enabled = true;
                btnEliminar.Enabled = true;
                btnBuscar.Enabled = true;
                btnLimpiar.Enabled = true;
                btnAceptar.Enabled = false;
                btnCancelar.Enabled = false;
            }
        }
    }
}
